package com.student.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.student.VO.PageInfoResult;
import com.student.dto.ResponseDto;
import com.student.mapper.SnackGoodsCateMapper;
import com.student.pojo.SnackGoodsCate;
import com.student.pojo.Zimu;
import com.student.service.SnackGoodsCateService;
import com.student.util.PageResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: makeups
 * @BelongsPackage: com.student.service.impl
 * @Author: 小徐
 * @CreateTime: 2024-12-21 17:31
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class SnackGoodsCateServiceImpl implements SnackGoodsCateService {

    @Autowired
    private SnackGoodsCateMapper snackGoodsCateMapper;

    @Override
    public ResponseDto getAllSnackType(SnackGoodsCate snackGoodsCate) {
        //        mybatis自带的分页插件，按照名字做排序
        PageHelper.startPage(snackGoodsCate.getCurrentPage(), snackGoodsCate.getPageSize());
        List<SnackGoodsCate> snackGoodsCates = snackGoodsCateMapper.getAllSnackTypeAdmin(snackGoodsCate);

        PageInfo<SnackGoodsCate> cyCardPageInfo = new PageInfo<>(snackGoodsCates);

        PageInfoResult result = PageResultUtils.getResult(cyCardPageInfo);

        System.out.println(result);
        return ResponseDto.success(result);
    }

    @Override
    public ResponseDto addSnackType(SnackGoodsCate snackGoodsCate) {
        SnackGoodsCate goodsCate = snackGoodsCateMapper.select(snackGoodsCate);
        if (goodsCate == null) {
            Integer res = snackGoodsCateMapper.addSnackType(snackGoodsCate);
            System.err.println("测试id");
            System.err.println(snackGoodsCate.getId());
            if (res > 0) {
                return ResponseDto.success(null);
            }
        }


        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto deleteSnackType(Integer id) {
        Integer res =snackGoodsCateMapper.deleteSnackType(id);
        if (res>0){
            return ResponseDto.success(null);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto updateSnackType(SnackGoodsCate snackGoodsCate) {
        Integer res =snackGoodsCateMapper.updateSnackType(snackGoodsCate);
        if (res>0){
            return ResponseDto.success(null);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto getAllType() {
        List<SnackGoodsCate> snackGoodsCates = snackGoodsCateMapper.getAllSnackType();
        return ResponseDto.success(snackGoodsCates);
    }

    @Override
    public ResponseDto getAllzimu() {
        List<Zimu> snackGoodsCates = snackGoodsCateMapper.getAllzimu();
        return ResponseDto.success(snackGoodsCates);
    }
}